﻿using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Domain.Entitys.DB;
using Domain.Entitys.Inv;
using Domain.IRepositorys.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.DB
{
    /// <summary>
    /// Appliaction下面的仓库类(实现Domain下面的接口)
    /// </summary>
    public class Db_warehouseServices: IDb_warehouseServices
    {

        private readonly DB_warehouse db_warehouse;
    
        private readonly IMapper mapper;

        public Db_warehouseServices(DB_warehouse db_warehouse, IMapper mapper) { 
            this.db_warehouse = db_warehouse;
            this.mapper= mapper;
        }
        /// <summary>
        /// 仓库分页查询
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="warehouse_name"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Warehouse> Select_fy_warehouse(string warehouse_code, string warehouse_name, int currentPage, int pageSize)
        {
            return db_warehouse.Select_fy_warehouse(warehouse_code, warehouse_name, currentPage, pageSize);
        }
        /// <summary>
        /// 仓库总数查询
        /// </summary>
        public int Select_count_warehouse(string warehouse_code, string warehouse_name)
        {
            return db_warehouse.Select_count_warehouse(warehouse_code, warehouse_name);
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> warehouse_tombstone(string warehouse_code)
        {
            return db_warehouse.warehouse_tombstone(warehouse_code);
        }
        /// <summary>
        /// 修改冻结状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="Warehouse_freeze"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> warehouse_Frozenstate(int id, char Warehouse_freeze)
        {
            return db_warehouse.warehouse_Frozenstate(id, Warehouse_freeze);
        }
        /// <summary>
        /// 仓库编码唯一性判断
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Warehouse_code_judgment(string warehouse_code)
        {
           return db_warehouse.Warehouse_code_judgment(warehouse_code);
        }
        /// <summary>
        /// 仓库名称唯一性判断
        /// </summary>
        /// <param name="warehouse_name"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Warehouse_name_judgment(string warehouse_name)
        {
           return db_warehouse.Warehouse_name_judgment(warehouse_name);
        }
        /// <summary>
        /// 仓库添加
        /// </summary>
        /// <param name="db_WarehouseAddDto"></param>
        /// <returns></returns>
        public Task<int> Warehouse_add(Db_warehouseAddDto db_WarehouseAddDto)
        {
           Warehouse warehouse = mapper.Map<Warehouse>(db_WarehouseAddDto);
            return db_warehouse.Warehouse_add(warehouse);
        }
        /// <summary>
        /// 仓库修改
        /// </summary>
        /// <param name="db_WarehouseUpdateDto"></param>
        /// <returns></returns>
        public Task<int> Warehouse_update(Db_warehouseUpdateDto db_WarehouseUpdateDto)
        {
            Warehouse warehouse = mapper.Map<Warehouse>(db_WarehouseUpdateDto);
            return db_warehouse.Warehouse_update(warehouse);
        }

        /// <summary>
        /// 分页条件查询产品库存信息
        /// </summary>
        /// <param name="productName"></param>
        /// <param name="dict_code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public Task<List<inv_stock>> GetInv_StockAsync(string productName, int dict_code, int currentPage, int pageSize)
        {
            return db_warehouse.GetInv_StockAsync(productName,dict_code,currentPage,pageSize);
        }

        /// <summary>
        /// 条件查询产品库存总数
        /// </summary>
        /// <param name="productName"></param>
        /// <param name="dict_code"></param>
        /// <returns></returns>
        public Task<int> Inv_StockCountAsync(string productName, int dict_code)
        {
            return db_warehouse.Inv_StockCountAsync(productName,dict_code);
        }

        /// <summary>
        /// 根据产品编号查询产品库存信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public Task<inv_stock> GetInv_StockByCodeAsync(string code)
        {
            return db_warehouse.GetInv_StockByCodeAsync(code);
        }
        /// <summary>
        /// 查询全部信息
        /// </summary>
        /// <returns></returns>
        public List<Warehouse> WarehouseBy_Select_Async()
        {
            return db_warehouse.WarehouseBy_Select_Async();
        }
        

        /// <summary>
        /// 根据传递的参数修改仓库关联信息
        /// </summary>
        /// <param name="db_Weahouse_CapacityUpdateDtos"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Warehouse_update_liaison(List<Db_Weahouse_capacityUpdateDto> db_Weahouse_CapacityUpdateDtos)
        {
            return db_warehouse.Warehouse_update_liaison(db_Weahouse_CapacityUpdateDtos);
        }

        /// <summary>
        /// 查询全部库存信息--盘点
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        public List<Warehouse> WarehouseBy_Selectpd() {
            return db_warehouse.WarehouseBy_Selectpd();
        }
        /// <summary>
        ///  修改仓库内量--增加
        /// </summary>
        /// <param name="db_Weahouse_CapacityUpdateDtos"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Warehouse_update_liaison_newly(List<Db_Weahouse_capacityUpdateDto> db_Weahouse_CapacityUpdateDtos)
        {
            return db_warehouse.Warehouse_update_liaison_newly(db_Weahouse_CapacityUpdateDtos);
        }


        /// <summary>
        /// 结构编码查询仓库信息
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        public List<Warehouse> WarehouseBy_Select_Async_code(string warehouse_code) { 
        
        return db_warehouse.WarehouseBy_Select_Async_code(warehouse_code);
        }


        /// <summary>
        /// 修改的时候,仓库名称唯一性判断
        /// </summary>
        /// <param name="warehouse_name"></param>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        public Task<int> Warehouse_name_UpdateJudgment(string warehouse_name, string warehouse_code) { 
        
        
        return db_warehouse.Warehouse_name_UpdateJudgment(warehouse_name, warehouse_code);
        }

        /// <summary>
        /// 根据产品编号库位查询产品库存信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public Task<inv_stock> GetInv_StockByCodeLocationCodeAsync(string code, string LocationCode)
        {
            return db_warehouse.GetInv_StockByCodeLocationCodeAsync(code, LocationCode);
        }
    }
}
